/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.engagesoft.cashflow.bean;

import com.engagesoft.cashflow.entidades.Usuario;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author rchajin
 */
@Stateless
public class UsuarioFacade extends AbstractFacade<Usuario> {
    @PersistenceContext(unitName = "com.engagesoft_CashFlow_war_1.0PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsuarioFacade() {
        super(Usuario.class);
    }

    public Usuario buscarPorId(int id) {
        Usuario usr = new Usuario();
        
        try {
            Query q = em.createNamedQuery("Usuario.findByIdUsuario").setParameter("idUsuario", id);
            for (Usuario u : (List<Usuario>) q.getResultList()) {
                usr = u;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return usr;
    }    
}
